Newer
Older
TheVengeance-Project-IADE-Unity2D / Assets / Scripts / NPC / Boss Sime / BossSlimeMeleeAttack.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class BossSlimeMeleeAttack : MonoBehaviour
{
    //Files
    private PlayerLife playerLife;
    private PlayerController playerController;

    //Floats
    public float meleeAttackCooldownTime = 0.8f;
    private float meleeAttackTimer = 0;

    //Ints
    public int meleeBossSlimeAttack = 10;

    void Start()
    {
        //Files
        playerLife = FindObjectOfType<PlayerLife>();
        playerController = FindObjectOfType<PlayerController>();
    }

    void Update()
    {
        if (meleeAttackTimer >= 0)
        {
            meleeAttackTimer -= Time.deltaTime;
        }
    }

    public void OnTriggerStay2D(Collider2D collision)
    {
        if (collision.tag == "Player" && meleeAttackTimer <= 0)
        {
            if (playerController.shield == true && meleeBossSlimeAttack > playerController.defensePlayer) //if player is blocking but the attack value is bigger than the defense value
            {
                playerLife.life -= meleeBossSlimeAttack - playerController.defensePlayer;

                playerController.flashActive = true;
                playerController.flashCounter = playerController.flashLength;
            }
            else if (playerController.shield == false) //if player isn't blocking
            {
                playerLife.life -= meleeBossSlimeAttack;
            }
            meleeAttackTimer = meleeAttackCooldownTime;
        }
    }
}